import { EnhancedAIService } from '../services/EnhancedAIService';
import { AIProvider } from '../types';

/**
 * 测试DeepSeek API连接
 */
export async function testDeepSeekAPI(apiKey: string): Promise<{ success: boolean; error?: string }> {
  try {
    const aiService = new EnhancedAIService();
    const result = await aiService.testConnection('deepseek' as AIProvider, apiKey);
    return result;
  } catch (error) {
    return {
      success: false,
      error: error instanceof Error ? error.message : '测试失败'
    };
  }
}

/**
 * 验证API密钥格式
 */
export function validateDeepSeekAPIKey(apiKey: string): { valid: boolean; error?: string } {
  if (!apiKey || !apiKey.trim()) {
    return { valid: false, error: 'API密钥不能为空' };
  }
  
  if (!apiKey.startsWith('sk-')) {
    return { valid: false, error: 'DeepSeek API密钥应该以"sk-"开头' };
  }
  
  if (apiKey.length < 20) {
    return { valid: false, error: 'API密钥长度不足' };
  }
  
  return { valid: true };
}